/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
        if(headA==nullptr||headB==nullptr) return nullptr;
        ListNode* aa=headA;
        ListNode* bb=headB;
        while(aa!=bb){
            aa=aa==nullptr?headB:aa->next;
            bb=bb==nullptr?headA:bb->next;
        }
        return aa;
    }
};